package com.kaiji.action;

import com.kaiji.entity.UserEntity;
import com.kaiji.service.UserService;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;

import javax.annotation.Resource;
import java.util.List;


public class UserAction extends ActionSupport {

    private static final Logger LOGGER = Logger.getLogger(UserAction.class);

    @Resource
    private UserService userService;

    @Action("user_index")
    public String index() {
        try {
            UserEntity userEntity = new UserEntity();
            userEntity.setUserName("开机");
            userEntity.setPhone("15102760632");
            userService.save(userEntity);


            List<UserEntity> userList = userService.getList();

            for (UserEntity user: userList) {
                System.out.println("id: " + user.getId());
                System.out.println("userName: " + user.getUserName());
                System.out.println("phone: " + user.getPhone());
                System.out.println("------------------------------");
            }
            System.out.println("hello struts2 and spring and hibernate!!!");
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error(e.getMessage());
        }

        return  null;
    }
}
